package com.tender.desensitization.factory.instance;

import com.google.common.collect.Lists;
import com.tender.desensitization.filter.FieldFilter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ClassUtils;

import java.time.temporal.Temporal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Slf4j
public abstract class AbstractUserWrapperProcessFactory implements TypeProcessFactory {

    private TypeProcessFactoryFacade factoryFacade;

    /**
     * 不同的工厂，筛选不同的注解标注的 Field
     */
    public AbstractUserWrapperProcessFactory(TypeProcessFactoryFacade factoryFacade, FieldFilter fieldFilter) {
        this.factoryFacade = factoryFacade;
        includeTypeFilters.add(fieldFilter);
    }

    public TypeProcessFactoryFacade getFactoryFacade() {
        return factoryFacade;
    }

    public List<FieldFilter> getIncludeTypeFilters() {
        return includeTypeFilters;
    }

    private final List<FieldFilter> includeTypeFilters = Lists.newArrayList();

    @Override
    public boolean supports(Class<?> clazz) {
        return !(Set.class.isAssignableFrom(clazz)
                || List.class.isAssignableFrom(clazz)
                || Map.class.isAssignableFrom(clazz)
                || ClassUtils.isPrimitiveOrWrapper(clazz)
                || Date.class.isAssignableFrom(clazz)
                || Number.class.isAssignableFrom(clazz)
                || Temporal.class.isAssignableFrom(clazz)
                || String.class == clazz);
    }

}